package com.example.task1.ui.AllService.YouthStation;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.bean.PersonBean;
import com.example.task1.ui.BaseAdapter;

import java.util.List;

public class PersonAdapter extends BaseAdapter<PersonBean.DataDTO> {

    private List<PersonBean.DataDTO> data;

    private Context context;
    private TextView tvTitle;
    private TextView tvName;
    private TextView tvTime;

    public PersonAdapter(List<PersonBean.DataDTO> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    protected void setData(List<PersonBean.DataDTO> rows) {

    }

    @Override
    protected int getLayout() {
        return R.layout.personlist;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected List<PersonBean.DataDTO> getData() {
        return data;
    }

    @Override
    protected void onBind(myHolder holder, PersonBean.DataDTO date) {
        tvName.setText("---"+date.getAuthor());
        tvTitle.setText(date.getTitle());
        tvTime.setText("发布时间："+date.getCreateTime());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context,PersonDetailsActivity.class);
                intent.putExtra("id",date.getId());
                context.startActivity(intent);
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    private void initView(View itemView) {
        tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
        tvName = (TextView) itemView.findViewById(R.id.tv_name);
        tvTime = (TextView) itemView.findViewById(R.id.tv_time);
    }
}
